﻿using WCS.Infrastructure.EFCore;
using WCS.Service.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using WCS.Infrastructure.Dto.Response;

namespace WCS.Api.Admin.Controllers
{

    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(Roles = "admin")]
    public class BaseController : ControllerBase
    {
        protected readonly IUserService _userService;

        public BaseController(IUserService userService)
        {
            _userService = userService;
        }

        /// <summary>
        /// 获取当前登录用户
        /// </summary>
        /// <returns></returns>
        protected async Task<IActionResult> GetCurrentUser()
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var result = await _userService.GetUserByCodeAsync(code);
            return Ok(result);
        }
    }
}
